<template>
  <div class="assetpurchaselist">
    <mt-header fixed :title="title" style="height: 0.64rem;">
      <router-link to="/tool" slot="left">
        <mt-button icon="back">返回</mt-button>
      </router-link>
    </mt-header>
    <div class="content">
      <div class="page-navbar">
        <mt-navbar fixed class="page-part" v-model="selected">
          <mt-tab-item id="1"><span>待审批单据</span></mt-tab-item>
          <mt-tab-item id="2"><span>已审批单据</span></mt-tab-item>
        </mt-navbar>
        <!-- 固定资产待审批-->
        <mt-tab-container v-model="selected">
          <mt-tab-container-item id="1">
            <div class="tab-box">
              <ul  v-infinite-scroll="leftLoadData" v-if="selected == '1'" infinite-scroll-disabled="leftLoading"  infinite-scroll-distance="10">
                <li class="list-box" v-for="(ass,index) in getAssetsWaitingApprovalList" :key="index">
                  <div class="list-item" @click="goMedicalPurchaseDetail(ass)">
                    <div class="list-item-line">
                      <div class="left">单号</div>
                      <div class="right">{{ass.pro_no}}</div>
                    </div>
                    <div class="list-item-line">
                      <div class="left">日期</div>
                      <div class="right">{{ass.pro_date}}</div>
                    </div>
                    <div class="list-item-line list-item-line-2">
                      <div class="left">
                        <label>申购科室</label><span>{{ass.pro_apply_dept}}</span>
                      </div>
                      <div class="right">
                        <label>收货科室</label><span>{{ass.pro_keshi}}</span>
                      </div>
                    </div>
                    <div class="list-item-line">
                      <div class="left">供应商</div>
                      <div class="right">{{ass.pro_supplier}}</div>
                    </div>
                    <div class="list-item-line">
                      <div class="left">备注</div>
                      <div class="right">{{ass.pro_beizhu}}</div>
                    </div>
                  </div>
                  <div class="list-btn">
                    <div class="btns">
                      <button @click="auditTask(1,ass)">同意</button>
                      <button @click="auditTask(0,ass)">不同意</button>
                    </div>
                  </div>
                </li>
              </ul>
            </div>
          </mt-tab-container-item>
          <mt-tab-container-item id="2">
            <div class="tab-box">
              <ul   v-if="selected == '2'"   v-infinite-scroll="rightLoadData" infinite-scroll-disabled="rightLoading"  infinite-scroll-distance="10">
                <li class="list-box" v-for="(ass,index) in getAssetsHisList" :key="index">
                  <div class="list-item" @click="goMedicalHistoryPurchaseDetail(ass)">
                    <div class="list-item-line">
                      <div class="left">单号</div>
                      <div class="right">{{ass.pro_no}}</div>
                    </div>
                    <div class="list-item-line">
                      <div class="left">日期</div>
                      <div class="right">{{ass.pro_date}}</div>
                    </div>
                    <div class="list-item-line list-item-line-2">
                      <div class="left">
                        <label>申购科室</label><span>{{ass.pro_apply_dept}}</span>
                      </div>
                      <div class="right">
                        <label>收货科室</label><span>{{ass.pro_keshi}}</span>
                      </div>
                    </div>
                    <div class="list-item-line">
                      <div class="left">供应商</div>
                      <div class="right">{{ass.pro_supplier}}</div>
                    </div>
                    <div class="list-item-line">
                      <div class="left">备注</div>
                      <div class="right">{{ass.pro_beizhu}}</div>
                    </div>
                  </div>
                  <!-- <div class="list-btn">
                     <div class="btns">
                       <button>同意</button>
                       <button>不同意</button>
                     </div>
                   </div>-->
                </li>
              </ul>
            </div>
          </mt-tab-container-item>
        </mt-tab-container>
        <!-- 固定资产已审批-->

      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'page-navbar',
    data() {
      return {
        selected: '1', //配合 mt-navbar 使用
        pageVal: 1,//当前页
        pageSize: 3,//每页显示条数
        loading: true,
        loadingDom: false,
        title: '固定资产审批列表',
        assetsList: []//接口接收后台数据
      }
    },
    methods: {
      leftLoadData(){
        console.log('医耗已审批 列表 loadData');
        let page = this.$store.state.assetsPurchasePendingObject.page;
        this.$store.dispatch('getAssetsWaitingApprovalList',{page:page});
      },
      rightLoadData(){
        let page = this.$store.state.assetsPurchaseHistoryObject.page;
        this.$store.dispatch('getAssetsHistoryApprovalList',{page:page});
      },
      goMedicalPurchaseDetail(item) {//审批列表详情明细
        let purchaseId = item.id;
        let taskID = item.taskID;
        let params = {purchaseId: purchaseId, taskID: taskID};
        this.$router.push({name: 'toolListInfo', params: params});
      },
      goMedicalHistoryPurchaseDetail(item) {//历史审批列表详情明细
        let purchaseId = item.id;
        let taskID = item.taskID;
        let params = {purchaseId: purchaseId, taskID: taskID};
        this.$router.push({name: 'toolYHHInfo', params: params});
      },
      //点击审批
      auditTask(isAgree, item) {
        console.log('点击审批');
        console.log(isAgree);
        console.log(item);
        let payload = {taskID: item.taskID, sheetId: item.id, examineStatus: isAgree};
        this.$store.dispatch('auditAssetsPurchaseTask', payload);
      }
    },
    computed: {

      //固定资产待审批列表
      getAssetsWaitingApprovalList() {
        return this.$store.state.assetsWaitingApprovalList;
      },
      //固定资产已审批
      getAssetsHisList() {
        return this.$store.state.assetsHisList;
      },
      leftLoading(){
        let loadingValue = this.$store.state.assetsPurchasePendingObject.loading;
        console.log('pageLoading : '+loadingValue);
        return loadingValue;
      },
      rightLoading(){
        let loadingValue = this.$store.state.assetsPurchaseHistoryObject.loading;
        console.log('pageLoading : '+loadingValue);
        return loadingValue;

      }
    },
    mounted() {
      //待审批
      // this.$store.dispatch('getAssetsWaitingApprovalList');
      this.$store.dispatch('resetAssetsPurchaseListPage');
      //获取标题
    }
  }

</script>

<style scoped>
  /*背景*/
  .assetpurchaselist {
    background-color: #ebebeb;
  }

  /* 中部显示部分*/
  .content {
    margin-top: 0.64rem;
  }

  ul, li {
    margin: 0;
    padding: 0
  }

  .page-part {
    margin-top: 0.6rem;
  }

  .tab-box {
    height:5rem;
    margin-top: 0.44rem;
    padding-top: 0.1rem;
    /*overflow-y: scroll;*/
  }
  .tab-box > ul {overflow-y: scroll;height:100%;}

  .tab-box div {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
  }

  .list-box {
    margin-bottom: 0.07rem;
    background: #fff;
    padding-right: 0.07px;
    font-size: 0.13rem;
    color: #363636;

  }

  .list-item {

  }

  .list-item-line {
    height: 0.3rem;
    line-height: 0.3rem;
  }

  .list-item-line .left {
    float: left;
    width: 0.72rem;
    padding-left: 0.15rem;
  }

  .list-item-line .right {
    margin-left: 0.73rem;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    border-bottom: #ebebeb 1px solid;
  }

  .list-item-line-2 {
    display: flex;
  }

  .list-item-line-2 .left, .list-item-line-2 .right {
    flex: 1;
    margin: 0
  }

  .list-item-line-2 .left span {
    border-bottom: #ebebeb 1px solid;
  }

  .list-item-line-2 span {
    display: inline-block;
  }

  .list-item-line-2 .left span:last-child, .list-item-line-2 .right span:last-child {
    margin-left: 0.2rem;
  }

  .list-btns {
  }

  .list-btns .btns {
  }

  .btns {
    width: 100%;
    padding-top: 0.16rem;
    padding-bottom: 0.16rem;
    text-align: center;
    display: inline-block;
  }

  .btns button {
    border: 0;
    width: 0.63rem;
    height: 0.2rem;
    background: #4b659e;
    color: #fff;
    -webkit-border-radius: 0.04rem;
    -moz-border-radius:0.04rem;
    border-radius: 0.04rem;
  }
  .btns button:last-child{margin-left:1rem;}
  .btn-agree {
  }

  .btn-deny {
    margin-left: 0.2rem;
  }


</style>
